<template>
	<view>
		<!-- 状态栏 -->
		<view class="status" :style="{position:headerPosition}"></view>
		<view class="header" :style="{position:headerPosition}">
			<view class="addr">
				<view class="icon location"></view>{{city}}
			</view>
			<!-- <view class="input-box">
				<input placeholder="默认关键字" placeholder-style="color:#c0c0c0;" @tap="toSearch()" />
				<view class="yticon icon-sousuo"></view>
			</view> -->
			<!-- <view class="icon-btn">
				<view class="yticon icon-sousuo" @tap="toMsg"></view>
			</view> -->
		</view>
		<!-- 占位 -->
		<!-- <view class="place"></view> -->
		<view class="category-list">
			<!-- 左侧分类导航 -->
			<scroll-view scroll-y="true" class="left">
				<view class="row" v-for="(category,index) in categoryList" :key="category.id" :class="[index == showCategoryIndex ? 'on' : '']"
				 @tap="showCategory(index)">{{category.name}}</view>
			</scroll-view>
			<!-- 右侧子导航 -->
			<scroll-view scroll-y="true" class="right">
				<view class="category" v-for="(category,index) in categoryList" :key="category.id" v-show="index == showCategoryIndex">
					<view class="banner">
						<image :src="category.icon ? imgsrc + category.icon : '/static/img/category/banner.jpg'"></image>
					</view>
					<view class="list">
						<view class="box" v-for="(box,i) in category.infos" :key="i" @tap="toCategory(box)">
							<image :src="imgsrc + box.icon"></image>
							<view class="text">{{box.name}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	import Api from '@/common/api';
	//高德SDK
	import amap from '@/common/SDK/amap-wx.js';
	export default {
		data() {
			return {
				showCategoryIndex: 0,
				headerPosition: "fixed",
				city: "深圳",
				categoryList: [], //分类列表
				// imgsrc:Api.imgsrc,
				image: "/static/img_mi.png",
			}
		},
		onPageScroll(e) {
			//兼容iOS端下拉时顶部漂移
			if (e.scrollTop >= 0) {
				this.headerPosition = "fixed";
			} else {
				this.headerPosition = "absolute";
			}
		},
		onLoad() {
			this.loadData();
		},
		onReachBottom() {
			this.showCategoryIndex = this.showCategoryIndex + 1;

		},
		methods: {
			//消息列表
			toMsg() {
				uni.navigateTo({
					url: '../../msg/msg'
				})
			},
			//分类切换显示
			showCategory(index) {
				this.showCategoryIndex = index;
			},
			toCategory(e) {
				uni.setStorageSync('catName', e.name);
				uni.navigateTo({
					// url: '../../goods/goods-list/goods-list?cid='+e.id+'&name='+e.name,
					// url: `/mall/product/list?fid=${this.currentId}&sid=${sid}&tid=${tid}`
					url: '/mall/product/list?cid=' + e.id + '&name=' + e.name,
				});
			},
			//搜索跳转
			toSearch() {
				uni.showToast({
					title: "搜索功能暂未开放",
					icon: 'none'
				});
			},
			async loadData() {
				this.logining = true;
				var _this = this;
				let params = {};
				let data = await Api.apiCall('post', Api.goods.categoryList, params);
				if (data) {
					_this.categoryList = data;
				}
			}
		},
		computed: {
			imgsrc: function() {
				console.log(Api.imgsrc)
				return Api.imgsrc;
			}
		}
	}
</script>
<style lang="scss">
	.status {
		width: 100%;
		height: 0;
		position: fixed;
		z-index: 10;
		background-color: #fff;
		top: 0;
		/*  #ifdef  APP-PLUS  */
		height: var(--status-bar-height); //覆盖样式
		/*  #endif  */

	}

	.header {
		width: 100vw;
		padding: 0 30upx;
		height: 100upx;
		display: flex;
		align-items: center;
		position: fixed;
		top: 0;
		z-index: 10;
		background-color: #fff;
		/*  #ifdef  APP-PLUS  */
		top: var(--status-bar-height);
		/*  #endif  */

		.addr {
			width: 120upx;
			height: 60upx;
			flex-shrink: 0;
			display: flex;
			align-items: center;
			font-size: 28upx;

			.icon {
				height: 60upx;
				margin-right: 5upx;
				display: flex;
				align-items: center;
				font-size: 42upx;
				color: #ffc50a;
			}
		}

		.input-box {
			width: 100%;
			height: 60upx;
			background-color: #f5f5f5;
			border-radius: 30upx;
			position: relative;
			display: flex;
			align-items: center;

			.yticon {
				display: flex;
				padding-right: 30upx;
				align-items: center;
				justify-content: flex-end;
				position: absolute;
				top: 0;
				right: 0;
				width: 60upx;
				height: 60upx;
				font-size: 34upx;
				color: #c0c0c0;
			}

			input {
				padding-left: 28upx;
				height: 28upx;
				font-size: 28upx;
			}
		}
	}

	.category-list {
		width: 100%;
		margin-top: 100upx;
		height: calc(100vh - 100upx);
		/*  #ifdef  APP-PLUS  */
		margin-top: calc(100upx + var(--status-bar-height));
		height: calc(100vh - 100upx - var(--status-bar-height));
		/*  #endif  */
		background-color: #fff;
		display: flex;
		flex-flow: row nowrap;

		.left {
			flex: 0 0 190upx;
			// background-color: #f2f2f2;
			border-right: .5upx solid rgba(234, 234, 234, 1);
			box-sizing: border-box;

			.row {
				width: 100%;
				height: 90upx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 28upx;
				color: #3c3c3c;

				&.on {
					color: #FFBC21;
					font-size: 30upx;
					font-weight: 600;
					position: relative;

					&::before {
						content: '';
						position: absolute;
						left: 0;
						width: 12upx;
						height: 44upx;
						background-color: #FFBC21;
					}
				}
			}
		}

		.right {
			flex: 1;

			.category {
				width: 100%;
				padding: 0upx 30upx;

				.banner {
					width: 100%;
					height: 160upx;
					border-radius: 10upx;
					overflow: hidden;
					box-shadow: 0upx 5upx 20upx rgba(0, 0, 0, 0.3);

					image {
						width: 100%;
						height: 160upx;
					}
				}

				.list {
					width: 100%;
					margin-top: 50upx;
					padding: 0upx 30upx;
					display: flex;
					flex-wrap: wrap;
					justify-content: space-between;

					.box {
						width: 150upx;
						margin: 0upx 30upx 60upx 20upx;
						display: flex;
						justify-content: center;
						align-items: center;
						flex-wrap: wrap;

						image {
							width: 146upx;
							height: 146upx;
						}

						.text {
							margin-top: 5upx;
							width: 100%;
							display: flex;
							justify-content: center;
							font-size: 26upx;
						}
					}
				}
			}
		}
	}
</style>
